package config

import (
	"path"
	"path/filepath"
	"runtime"

	"github.com/illidaris/configuration"
)

func Get(key string) any {
	return configuration.Get(key)
}

func LoadConfig(configPath string) error {
	return configuration.LoadConfig(configPath, nil)
}

func DefaultConfig() error {
	var abPath string
	_, filename, _, ok := runtime.Caller(0)
	if ok {
		abPath = path.Dir(filename)
	}
	abPath = filepath.Join(abPath, "config.yml")
	return LoadConfig(abPath)
}

func Init() error {
	var abPath string
	_, filename, _, ok := runtime.Caller(0)
	if ok {
		abPath = path.Dir(filename)
	}
	var name = "config.yml"
	abPath = filepath.Join(abPath, name)
	err := LoadConfig(abPath)
	if err != nil {
		println(err)
	}
	return err
}
